package com.tuanbiao.blast;

import com.hzjq.core.Blast;
import com.hzjq.core.loader.OnCapUidConvertLoader;
import com.hzjq.lib.BlastKool;
import com.hzjq.lib.callback.OnConvertMillCallback;
import com.hzjq.lib.config.AppBuilder;
import com.hzjq.lib.config.param.BlastLoader;
import com.hzjq.lib.convert.CapUid21Convertor;
import com.hzjq.lib.convert.CapUidMill2Convertor;
import com.hzjq.lib.convert.CapUidMillQHConvertor;
import com.hzjq.lib.convert.CapUidQHConvertor;
import com.hzjq.lib.convert.DefaultCapUidConvert;
import com.tuanbiao.App;
import com.tuanbiao.AppConfig;
import com.tuanbiao.JQBlastConfig;
import com.tuanbiao.constants.Constants;
import com.tuanbiao.data.entity.CodeModelType;
import com.tuanbiao.utils.SPHelper;

import java.util.List;

import timber.log.Timber;

/**
 * @author abiao
 * @date 2022/7/20 19:19
 * @description:
 */
public class JQBlast {
    private static volatile JQBlast INSTANCE;
    private List<CodeModelType> codeModels;

    private JQBlast() {

    }

    public static JQBlast getInstance() {
        if (null == INSTANCE) {
            synchronized (JQBlast.class) {
                if (null == INSTANCE) {
                    INSTANCE = new JQBlast();
                }
            }
        }
        return INSTANCE;
    }

    public void init() {
        AppBuilder builder = BlastKool.Companion.init(App.getInstance())
                .setMapApiKey("e90622c6827926ae0f0cf3faaef14687")
                .setDebug(JQBlastConfig.isDebug())
                .setTargetVersion(JQBlastConfig.getBinTagVersion())
                .printSerialData(true)
                //
                .setUdt40SDebugAddress(JQBlastConfig.isUdt40SDebugAddress());
        if (AppConfig.isNoLogin()) {
            //免登录
            builder.enableNotUserLogin(JQBlastConfig.enableNotUserLogin())
                    //单机
                    .enableStandAloneModel(JQBlastConfig.enableStandAloneModel());
        }
        builder.build();
        //BlastKool.Companion.loader().setForceUpdateVersion(true);
        Timber.i("init:" + SPHelper.getCodeMode());
    }

    @Deprecated
    private void changeCodeModel(OnCapUidConvertLoader convertLoader) {
        Blast.Companion.getInstance().setOnCapUidConvertor(convertLoader);
    }

    @Deprecated
    private void setOnConvertMillCallback(OnConvertMillCallback callback) {
        BlastLoader.Companion.setOnConvertMillCallback(callback);
    }

    @Deprecated
    public void changeEnCodingModel(CodeModelType codeModelType) {
        Timber.i("changeEnCodingModel#" + codeModelType.itemName());
        SPHelper.setCodeMode(codeModelType.itemName());
        switch (codeModelType.itemName()) {
            case Constants.CodeModel.WEI_DONG:
                changeCodeModel(new CapUid21Convertor());
                setOnConvertMillCallback(new CapUidMill2Convertor());
                break;
            case Constants.CodeModel.XIAN_QINGHUA:
                changeCodeModel(new CapUidQHConvertor());
                setOnConvertMillCallback(new CapUidMillQHConvertor());
                break;
            default:
                changeCodeModel(new DefaultCapUidConvert());
                break;
        }
    }
}
